<template>
  <div class="deliveryTask">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">收货任务</span>
        <!--<el-button style="float: right;" type="primary" @click="dialogOpen()" v-if="USER.auth.indexOf('base_kuqu_add')!==-1">新增库区</el-button>-->
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="可用操作"
          width="120">
          <template slot-scope="s">
            <el-button type="success" size="mini" @click="dialogOpen(s.row)" v-if="s.row.asnzt==='0'&& s.row.shzt==='1'&& s.row.sczt==='0'">生成</el-button>
          </template>
        </el-table-column>
        <el-form-item label="名称" prop="gysmc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_gysmc"
                    placeholder="供应商名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="PO编号" prop="dycgdbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_dycgdbh"
                    placeholder="关联PO编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="ASN编号" prop="asnbh">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_asnbh"
                    placeholder="ASN编号" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" prop="cjsj">
          <el-date-picker
            v-model="autoVue_table_cjsj"
            type="daterange"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="ASN状态" prop="asnzt">
          <el-select v-model="autoVue_table_asnzt"
                     placeholder="ASN状态">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              v-for="item in DAOHUO.asnzt"
              :key="item.dictionaryid"
              :label="item.value"
              :value="item.dictionaryid">
            </el-option>
          </el-select>
        </el-form-item>
      </s-table>
    </el-card>
    <s-dialog :dialog="dialog" :close="dialogInit">
      <p slot="title">{{dialog.title}}收货任务</p>
      <s-form :form="formDialog" ref="formDialog">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" class="">
            <el-form-item prop="account" label="账户类型">
              <el-select v-model="formDialog.account" placeholder="请选择">
                <el-option
                  v-for="item in SHELVESTASK.account"
                  :key="item.dictionaryid"
                  :label="item.value"
                  :value="item.dictionaryid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}" class="">
            <el-form-item prop="ryid" label="人员">
              <el-select v-model="formDialog.ryid"
                         filterable
                         @change="dialogRemoteryid"
                         placeholder="请输入人员名称">
                <el-option
                  v-for="item in dialog.wmsqualityinspectionlist"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogSave">保存</el-button>
    </s-dialog>
  </div>
</template>

<script>
  import {AutoVue, AutoPromise} from '~/plugins/Tools';
  function __form () {
    return {
      account: { value: '', rule: [ 'vNull__change' ] },
      ryid: { value: '', rule: [ 'vNull__change' ] },
    };
  }
  export default AutoVue({
    name: 'task_deliveryTask-FEcarWms',
    head: {
      'title': '收货任务管理',
      'meta': [
        { 'hid': 'description', 'name': 'description', 'content': '乐速科技平台 收货任务 查看收货任务信息' },
      ],
    },
    store: ['USER', 'DAOHUO', 'SHELVESTASK', 'DICTIONARY_shelvestask'],
    data: {
      table: {
        column:
          [
            { label: '仓库',
              prop: 'ckmc',
              minWidth: '0px',
              cRemarks: '',
              search: false },
            { label: '货主',
              prop: 'hzmc',
              minWidth: '0px',
              cRemarks: '',
              search: false },
            { label: 'ASN编号',
              prop: 'asnbh',
              minWidth: '0px',
              cRemarks: '',
              search: true },
            { label: 'ASN类型',
              prop: 'show_asnlx',
              minWidth: '0px',
              cRemarks: '',
              search: false },
            { label: 'ASN状态',
              prop: 'show_asnzt',
              minWidth: '0px',
              cRemarks: '',
              search: true },
            { label: '优先级',
              prop: 'yxj',
              minWidth: '0px',
              cRemarks: '',
              search: false },
            { label: '预计到货时间',
              prop: 'yjdhsjks',
              minWidth: '0px',
              cRemarks: '',
              formatter: (row, column) => {
                return this.a.methods.formatterTime(row[column.property || column], 6);
              },
              search: false },
            { label: '创建时间',
              prop: 'cjsj',
              minWidth: '0px',
              cRemarks: '',
              type: 'DateRange',
              formatter: (row, column) => {
                return this.a.methods.formatterTime(row[column.property || column], 6);
              },
              search: true },
            { label: '审核状态',
              prop: 'show_shzt',
              minWidth: '0px',
              cRemarks: '',
              search: true },
            { label: '关联PO编号',
              prop: 'dycgdbh',
              minWidth: '0px',
              cRemarks: '',
              search: true },
            { label: '制单人',
              prop: 'zdr',
              minWidth: '0px',
              cRemarks: '',
              search: false },
            { label: '审核人',
              prop: 'ddshr',
              minWidth: '0px',
              cRemarks: '',
              search: false },
            { label: '码盘状态',
              prop: 'show_mpzt',
              minWidth: '0px',
              cRemarks: '0.未码盘 1.码盘',
              search: true },
            { label: '收货完成时间',
              prop: 'shwcsj',
              minWidth: '0px',
              cRemarks: '',
              formatter: (row, column) => {
                return this.a.methods.formatterTime(row[column.property || column], 6);
              },
              search: false },
            { label: '打印状态',
              prop: 'show_dyzt',
              minWidth: '0px',
              cRemarks: '',
              search: true },
            { label: '打印时间',
              prop: 'dysj',
              minWidth: '0px',
              cRemarks: '',
              formatter: (row, column) => {
                return this.a.methods.formatterTime(row[column.property || column], 6);
              },
              search: false },
            { label: '供应商名称',
              prop: 'gysmc',
              minWidth: '0px',
              cRemarks: '',
              search: true },
          ],
        url: '/wmsEstimatedArrivalOrder/list',
        key: 'id',
        tableColumn: 4,
        muti: false,
      },
      formDialog: __form(),
      dialog: {
        title: '生成',
        wmsqualityinspectionlist: '',
        row: {},
        ryid: '',
      },
    },
    transition: 'slide-fade',
    methods: {
      dialogInit () {
        this.formDialog = {
          ...this.formDialog,
          ...this.ObjectClone(__form()),
        };
        this.resetFields('formDialog');
      },
      async dialogOpen (row) {
        await AutoPromise([
          async () => {
            if (!this.DICTIONARY_shelvesTask) {
              await this.USE('DICTIONARY_shelvesTask');
            }
          },
        ]);
        this.dialog.row = row;
        this.dialog.visible = true;
      },
      async dialogRemoteryid (id) {
        this.dialog.wmsqualityinspectionlist.forEach(value => {
          console.log(value.id);
          console.log(id);
          if (id === value.id) {
            this.dialog.row.userName = value.name;
            this.dialog.row.ryid = value.id;
          }
        });
      },
      dialogSave () {
        if (this.formDialog.account === '0') {
          this.VALIDATE('formDialog', async option => {
            option.mpzt = this.dialog.row.mpzt;
            option.yxj = this.dialog.row.yxj;
            option.asnbh = this.dialog.row.asnbh;
            option.id = this.dialog.row.id;
            option.gysmc = this.dialog.row.gysmc;
            option.ryid = ',' + this.formDialog.ryid + ',';
            delete option.account;
            try {
              await this.post('/wmsReceiptTaskPda/save', option);
              this.tableWatch('table');
              this.dialogInit();
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          });
        } else {
          this.VALIDATE('formDialog', async option => {
            option.mpzt = this.dialog.row.mpzt;
            option.yxj = this.dialog.row.yxj;
            option.asnbh = this.dialog.row.asnbh;
            option.id = this.dialog.row.id;
            option.gysmc = this.dialog.row.gysmc;
            option.ryid = ',' + this.formDialog.ryid + ',';
            delete option.account;
            try {
              await this.post('/wmsReceiptTaskPda/save', option);
              this.tableWatch('table');
              this.dialogInit();
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          });
        }
      },
    },
    watch: {
      'formDialog.account': async function (account) {
        this.formDialog.ryid = '';
        if (account.length !== 0 && account === '0') {
          this.dialog.wmsqualityinspectionlist = await this.post('/wmsqualityinspectionlist/selectYh', {});
        }
        if (account.length !== 0 && account === '1') {
          let {contentList} = await this.post('/wmsqualityinspectionlist/selectPDADLByHz', {
          });
          this.dialog.wmsqualityinspectionlist = contentList;
        }
      },
    },
    mounted: async function () {
      this.tableWatch('table');
      await AutoPromise([
        async () => {
          if (!this.DICTIONARY_daohuo) {
            await this.USE('DICTIONARY_daohuo');
          }
        },
      ]);
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
</style>

<style lang="scss">

</style>
